package org.pidan.basic.designModel.observer;

/**
 * {@code @description}: TODO
 * {@code @author}: huangyuxin
 * {@code @date}: 2023-11-17
 */
public class Client {

    public static void main(String[] args) {

        // 目标对象
        RealObserver realObserver = new RealObserver();

        // 创建多个观察者
        ObserverImpl observer1 = new ObserverImpl();
        ObserverImpl observer2 = new ObserverImpl();
        ObserverImpl observer3 = new ObserverImpl();

        // 注册到观察队列中
        realObserver.registerObserver(observer1);
        realObserver.registerObserver(observer2);
        realObserver.registerObserver(observer3);

        // 改变State状态
        realObserver.setState(300);

        System.out.println("obs1观察者的MyState值为：" + observer1.getMyState());
        System.out.println("obs2观察者的MyState值为：" + observer2.getMyState());
        System.out.println("obs3观察者的MyState值为：" + observer3.getMyState());

        // 改变State状态
        realObserver.setState(500);

        System.out.println("obs1观察者的MyState值为：" + observer1.getMyState());
        System.out.println("obs2观察者的MyState值为：" + observer2.getMyState());
        System.out.println("obs3观察者的MyState值为：" + observer3.getMyState());
    }
}
